<?php
namespace App\Http\Controllers\Client\Shop\Explore;

use App\Http\Controllers\ClientController;
use App\Models\Tools\AliOss;
use App\Models\Tools\Data;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ExploreTaskDetailController extends ClientController
{

    /**
     * 接单前的任务
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {

        $all = $this->all;

        $eo_id = $all['eo_id'];

        try {
            $order_message = DB::table('explore_order')->where('eo_id','=',$eo_id)->first();
            $order_message = json_decode(json_encode($order_message), true);

            $shop_message = DB::table('shop')->where('shop_id','=',$order_message['shop_id'])->first();
            $shop_message = json_decode(json_encode($shop_message), true);

            $shop_message['shop_name_mask'] = mb_substr($shop_message['shop_name'],'4'); // 前两个字在客户端加*
            $result = array_merge($order_message,$shop_message);
            $result['head_img'] = AliOss::getUrl($result['head_img']);
            $result['shop_name'] =  $shop_message['shop_name'];
            $result['shop_name_mask'] = $shop_message['shop_name_mask'];
            $result['shop_type_name'] = Data::$laifeiShopTypes[$shop_message['shop_type']];
            $link_url = explode('/',$shop_message['link_url']);
            $result['link_url_code'] = array_pop($link_url);
            $result['short_name'] = DB::table('dict_area')->where('id','=',$shop_message['district'])->value('short_name');
            return $this->setReturnJson(0,'success',$result);
        } catch (\Exception $e) {
            Log::error(ExploreTaskDetailController::class, ['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1, '查询失败');
        }

    }

}
